package com.example.hasee.plant.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.example.hasee.plant.R;
import com.example.hasee.plant.model.SaveDataModel;

import org.w3c.dom.Text;

import java.util.List;

/**
 * Created by hasee on 2017-02-03.
 */

public class DataListAdapter extends BaseAdapter {
    private Context context;
    List<SaveDataModel> list;
    private LayoutInflater layoutInflater;
    public DataListAdapter(Context context, List<SaveDataModel> list){
        this.context=context;
        this.list=list;
        layoutInflater=LayoutInflater.from(context);
    }
    @Override
    public int getCount() {
        return list!=null?list.size():0;
    }

    @Override
    public Object getItem(int i) {
        return list.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int position, View view, ViewGroup viewGroup) {
        ViewHolder holder;
        SaveDataModel saveDataModel=list.get(position);
        if(view==null){
            view=layoutInflater.inflate(R.layout.datalist_item,viewGroup,false);
            holder=new ViewHolder();
            holder.tv_bianhao= (TextView) view.findViewById(R.id.tv_bianhao);
            holder.tv_lujing= (TextView) view.findViewById(R.id.tv_lujing);
            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }
        holder.tv_bianhao.setText(saveDataModel.getNum()+"");
        holder.tv_lujing.setText(saveDataModel.getImgPath()+"||"+saveDataModel.getRecordPath()+"||"+saveDataModel.getVideoPath());
        return view;
    }

    class ViewHolder{
        TextView tv_bianhao;
        TextView tv_lujing;
    }
}
